﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.IO;
using QuickTasks.ViewModels.Properties;
using QuickTasks.ViewModels.Data;
using Microsoft.Advertising.Mobile.UI;

namespace QuickTasks.Views
{
    public partial class CompletedTask : PhoneApplicationPage
    {
        ToDoListData objtodo = new ToDoListData();
        string listid = null;
        int taskcount = 10;

        #region Constructor
        public CompletedTask()
        {
            InitializeComponent();
         
        }

        #endregion

        #region pageload

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                lbxCompletedTasks.ItemsSource = objtodo.LoadCompletedTasks(taskcount);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in PhoneApplicationPage_Loaded event In CompletedTask.xaml page", ex);
            }
        }

        

        #endregion
   
        private void lbxCompletedTasks_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (lbxCompletedTasks.SelectedIndex != -1)
                {
                    string title = (lbxCompletedTasks.SelectedItem as ToDoListProper).Name;

                    if (title == "get more")
                    {
                        taskcount = taskcount + 10;
                        lbxCompletedTasks.ItemsSource = objtodo.LoadCompletedTasks(taskcount);
                        lbxCompletedTasks.ScrollIntoView(lbxCompletedTasks.Items[taskcount - 10]);
                    }
                    else
                        NavigationService.Navigate(new Uri("/Views/CompletedTask/CompleteTaskDetail.xaml?listid=" + (lbxCompletedTasks.SelectedItem as ToDoListProper).Id, UriKind.Relative));
                }
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in lbxCompletedTasks_SelectionChanged event In CompletedTask.xaml page", ex);
            }
    }

    }
}

